package com.chocho.consumeserver.utils;

import com.alibaba.fastjson.JSON;
import com.chocho.consumeserver.service.GetwayService;
import com.chocho.consumeserver.vo.Code;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;


/**
 * 主要从消息队列中接收消息
 */
@Component
public class MQReceiver {
    @Autowired
    private GetwayService getwayService;

    private Logger logger = LoggerFactory.getLogger(MQReceiver.class);

    /**
     * 用于接收处理消息
     *
     * @param message
     */
    public void receiveMessage(String message) {
        logger.debug("===========>接收消息!");
        Code code = JSON.parseObject(message, Code.class);
        //从消息队列中接收到的消息全部是游客提交的
        try {
            getwayService.javaCompile(code);
            logger.info("调用接收接口");
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            //发送报警
            throw new RuntimeException("编译失败!");
        }
    }


}